<template>
  <div id="maintopLeft">
    <div class="title clearfix">
      <h2 class="left">{{name}}</h2>
      <div class="btn-search left">
        <input
          type="text"
          name="search"
          placeholder="输入床位，病情等关键词"
          v-model="searchVal"
          @change="searchValue"
        />
        <img
          src="../../../../static/images/search.png"
          height="18"
          width="18"
          alt
          @click="btnSearch"
        />
      </div>
    </div>
    <p class="currentNum">
      当前人数:
      <span class="patient-num" style="margin-left:15px;font-size:16px;">{{TotalCount}}</span>
    </p>
  </div>
</template>
<script>
import Bus from "@/components/common/bus"; //引入公共媒介JS BUS
export default {
  data() {
    return {
      TotalCount: "",
      searchVal: "",
      name: ""
    };
  },
  watch: {
    $route: {
      handler(val, oldval) {
        if (val.path.indexOf("/inpatientsAll/inpatientsAllList") != -1) {
          this.name = "所有患者";
        } else if (val.path.indexOf("/collection/collectionList") != -1) {
          this.name = "我的收藏";
        } else {
          this.name = "在科患者";
        }
      }
    }
  },
  created() {
    this.isRouter();
  },
  methods: {
    isRouter() {
      if (this.$route.path.indexOf("/inpatientsAll/inpatientsAllList") != -1) {
        this.name = "所有患者";
      } else if (this.$route.path.indexOf("/collection/collectionList") != -1) {
        this.name = "我的收藏";
      } else {
        this.name = "在科患者";
      }
    },
    btnSearch() {
      Bus.$emit("searchVal", this.searchVal);
    },
    searchValue() {
      if (this.searchVal == "") {
        Bus.$emit("searchVal", "");
      }
    }
  },
  mounted() {
    Bus.$on("TotalCount", e => {
      this.TotalCount = e;
      //  console.log(`传来的数据是：${e}`)
    });
  }
};
</script>
<style scoped>
#maintopLeft {
  position: relative;
  width: 60%;
  height: 100%;
}
#maintopLeft h2 {
  font-weight: 500;
  margin-top: 0;
  margin-bottom: 0;
  line-height: 30px;
  height: 30px;
  margin-right: 30px;
  letter-spacing: 3px;
}
#maintopLeft .title {
  position: absolute;
  top: 50%;
  transform: translateY(-70%);
  left: 22%;
  width: 78%;
}
#maintopLeft > p {
  position: absolute;
  bottom: -2px;
  height: 30px;
  line-height: 30px;
  left: 21%;
  border-bottom: 2px solid #11a7f3;
  padding: 0 15px;
}
.btn-search {
  width: 220px;
  height: 34px;
  border: 1px solid #ccc;
  border-radius: 15px;
  padding-left: 10px;
  vertical-align: top;
}
.btn-search input {
  height: 32px;
  width: 92%;
  width: -moz-calc(95% - 18px);
  width: -webkit-calc(95% - 18px);
  width: calc(95% - 18px);
  border: none;
}

@media (max-width: 768px) {
  .btn-search {
    width: auto;
    height: auto;
    border: 1px solid #ccc;
    border-radius: 15px;
    padding-left: 10px;
    vertical-align: top;
    float: initial;
    width: 220px;
  }
  .btn-search input {
    height: auto;
    border: none;
  }
  
  #maintopLeft{
    width: 100%;
    height: auto;
  }
  .currentNum{
    display: none;
  }
  #maintopLeft .title{
    position: initial;
    transform: initial;
    width: 100%;
    padding: 0 15px;
  }
  #maintopLeft h2{
    float: initial;
  }
}


</style>
